package com.example.administrator.myapplication;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2020/11/16.
 */


public class TowActivity extends AppCompatActivity{
    private String[]titles={"java","php","python","html","css"};
    private String[]contents={"2020.11.16","2020.11.17","2020.11.18","2020.11.19","2020.11.20"};
    private ListView listView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tow);
        initView();
        initData();
        initEvent();
    }
    private void initView(){
        listView = findViewById(R.id.listview);
        listView.setAdapter(new TowBaseAdapter());
    }
    private void initData(){

    }
    private void initEvent(){
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(TowActivity.this, "我点击了条目(下标还是，当前的位置)"+i, Toast.LENGTH_SHORT).show();
            }
        });
    }
    class TowBaseAdapter extends BaseAdapter{

        private TextView title;

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int i) {
            return titles[i];
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            view=View.inflate(TowActivity.this,R.layout.item_two_layout,null);
            TextView title=view.findViewById(R.id.item_title_tv);
            TextView content=view.findViewById(R.id.item_conten_tv);
            title.setText(titles[i]+"");
            content.setText(contents[i]+"");
            return view;
        }
    }
}
